<?php 
require_once("../../system/conf/config.php") ;
require_once($configs["framework_dir"]."/include/header_no.php") ;
require_once("../../system/include/header_no.php") ;
?>

<SCRIPT LANGUAGE="JavaScript">
<!--
function goNext(){
	var matrix = document.form1.elements ;
	for(var i=0;i<matrix.length;i++){
		var e = matrix[i] ;
		if(e.type == "checkbox"){
			if(!e.checked){
				e.checked = true ;
				e.value = "0";
			}
		}
	}
	document.form1.submit() ;
}
//-->
</SCRIPT>


<CENTER>
<BR><BR>
<div style="width:98%">
<?php

$tableName = get("tableName");
$file = getRealPath("../../system/labels")."/".$tableName."_labels.php" ;
if(file_exists($file)){
	require_once($file);
}

$targetFolder = str_replace("\\","/",getRealPath("../../system/"))."/";

// echo $targetFolder;

?>

<FORM name="form1" METHOD=POST ACTION="autopage_3.php">
<INPUT TYPE="hidden" name='tableName' value='<?=get("tableName")?>'>
<TABLE>
<TR>
	<TD>Table Name:</TD>
	<TD><INPUT TYPE="text" class="text" NAME="entityName" value="<?=$tableName?>"></TD>
</TR>
<TR>
	<TD>File Path:</TD>
	<TD>
		<select name="targetFolder">
		<?php

		$currentPath = $targetFolder ;
		if (($d = dir($currentPath)) != ""){ 
			while($file = $d->read()){
				if ($file == '.' || $file == '..' || $file == '.svn'){
				   continue ;
				}
				$fileName = $file ;
				$full = $currentPath.$file ;
				$isDir = is_dir("$full") ;
				if($isDir){
					echo "<option value='$full'>$full</option>";
				}
			}
		}
		
		?>
		</select>

	</TD>
</TR>
</TABLE>
<BR><BR>

<TABLE class="table_list" cellspacing="0" cellpadding="0">
<TR>
	<th class=col_title></th>
	<th class=col_title>Field</th>
	<th class=col_title>Label Name</th>
	<th class=col_title>Not Null</th>
	<th class=col_title>Value Type</th>
	<th class=col_title>Searchable</th>
	<th class=col_title>List</th>
	<th class=col_title>List Width</th>
	<th class=col_title>Help Info</th>
</TR>

<?php
$sqlstr = "select * from $tableName where 1=1";
// echo $sqlstr ;
@mysql_connect($company["db_host"],$company["db_user"],$company["db_pass"]);
mysql_select_db($company["db_name"]);
$result = mysql_query($sqlstr);

$i = 0;
while ($i < mysql_num_fields($result)) {
  //  echo "Information for column $i:<br />\n";
    $meta = mysql_fetch_field($result);
    if (!$meta) {
        echo "No information available<br />\n";
    }
	$label = $meta->name ;
	$labelKey = $tableName . "." . $label ;
	if(array_key_exists($labelKey,$titles)){
		$label = label($labelKey);
	}
?>
	<TR class='row_0' onmouseover="this.className='row_2'" onmouseout="this.className='row_0';">
		<TD class=col_l>
			<?php
			echo "<input type=hidden name='column_name[]' value='".$meta->name."'>\n";
			echo "<input type=hidden name='primary_key[]' value='".$meta->primary_key."'>\n";
			echo "<input type=hidden name='multiple_key[]' value='".$meta->multiple_key."'>\n";
			echo "<input type=hidden name='numeric[]' value='".$meta->numeric."'>\n";
			echo "<input type=hidden name='unique_key[]' value='".$meta->unique_key."'>\n";
			echo "<input type=hidden name='unsigned[]' value='".$meta->unsigned."'>\n";
			echo "<input type=hidden name='zerofill[]' value='".$meta->zerofill."'>\n";
			echo "<input type=text name='max_length[]' value='".$meta->max_length."'>\n";
			echo "<input type=hidden name='type[]' value='".$meta->type."'>\n";
			?>
		</TD>
		<TD class=col_l><?= $meta->name ?> <?=$meta->type?></TD>
		<TD class=col_l>
			<INPUT TYPE="text" class="text" r_name="" r_type="" not_null="yes" maxlength="" size="23" NAME="field_name[]" value="<?=$label?>">
		</TD>
		<TD class=col_l>
			<?php
			$checked = $meta->not_null == 1 ? " checked" : "" ;
			echo "<input type='checkbox' name='not_null[]' value='1' $checked>" ;
			?>

		</TD>
		<TD class=col_l>
			<?php
				echo getRTYPEOptions($meta->name,$meta->type,$meta->max_length);
			?>
		</TD>
		<TD class=col_l>
			<?php
			$checked = $meta->not_null == 1 ? " checked" : "" ;
			echo "<input type='checkbox' name='searchable[]' value='1' $checked>" ;
			?>
		</TD>
		<TD class=col_l>
			<?php
			$checked = $meta->not_null == 1 ? " checked" : "" ;
			echo "<input type='checkbox' name='listable[]' value='1' $checked>" ;
			?>
		</TD>
		<TD class=col_l><INPUT TYPE="text" class="text" r_name="" r_type="int" not_null="no" maxlength="3" size="8" NAME="width[]"></TD>
		<TD class=col_l><INPUT TYPE="text" class="text" r_name="" r_type="" not_null="no" maxlength="" size="16" NAME="remark[]"></TD>
	</TR>
<?php
	$i++;
}

mysql_free_result($result);
unset($result);

?>
</TABLE>

<BR><BR>
<input type=button class='btn bback' value='Back' onclick="go_url('autopage_1.php')">
<input type=button class='btn bsubmit' value='Next' onclick='goNext()'>
<input type=reset  class='btn breset' value='Reset'>

</FORM>

</div>
</CENTER>
<?php
require_once($configs["framework_dir"]."/include/footer_no.php") ;
?>